package cn.wolfcode.web.controller;


import cn.wolfcode.domain.SystemLog;
import cn.wolfcode.qo.SystemLogQueryObject;
import cn.wolfcode.service.ISystemLogService;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/systemLog")
public class SystemLogController {

    @Autowired
    private ISystemLogService systemLogService;


    @RequiredPermission(name="日志页面",expression="systemLog:list")
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") SystemLogQueryObject qo){
        PageInfo<SystemLog> pageInfo = systemLogService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "systemLog/list";
    }


    @RequiredPermission(name="日志删除",expression="systemLog:delete")
    @RequestMapping("/delete")
    public String delete(Long id) {
        if (id != null) {
           systemLogService.delete(id);
        }
        return "redirect:/systemLog/list";
    }


    @RequiredPermission(name="日志新增/编辑",expression="systemLog:saveOrUpdate")
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(SystemLog systemLog) {
        if (systemLog.getId() == null) {
            systemLogService.save(systemLog);
        } else {
            systemLogService.update(systemLog);
        }
        return "redirect:/systemLog/list";
    }


    @RequiredPermission(name="日志新增/编辑跳转",expression="systemLog:saveOrUpdate")
    @RequestMapping("/input")
    public String input(Long id, Model model) {
        if (id != null) {
            model.addAttribute("systemLog",systemLogService.get(id));
        }
        return "systemLog/input";
    }
}
